package com.changhai.diabetes.service.impl;

import com.changhai.diabetes.model.Family;
import com.changhai.diabetes.service.FamilyService;
import com.changhai.diabetes.util.Constants;

/**
 * 家族史
 * 
 * @author Andy
 * 
 */
public class FamilyServiceImpl extends CommonServiceImpl implements FamilyService {
	public Family searchByPatientId(Long patientid){
		Object o = this.getObject(Constants.DS_CHANGHAI, "family.getByPatientId", patientid);
		if (o != null && o instanceof Family) {
			return (Family) o;
		} else {
			Family f = new Family();
			f.setPatientid(patientid);
			return f;
		}
	}
	
	public void saveEditFamily(Family family){
		if(family!=null){
			if(family.getFamilyid()!=null){
				this.updateObject(Constants.DS_CHANGHAI, "family.updateByPrimaryKey", family);
			}else{
				Long fid = this.saveNewFamily(family);
				if (fid != null && fid > 0) {
					family.setFamilyid(fid);
					this.updateObject(Constants.DS_CHANGHAI, "family.updateByPrimaryKey", family);
				}
			}
		}
	}
	
	public Long saveNewFamily(Family family){
		Integer id = 0;
		if (family != null && family.getPatientid()!=null) {
			id = this.insertObjectID(Constants.DS_CHANGHAI, "family.insert", family);
		}
		return new Long(id);
	}
}
